import $antProcess from '@/utils/ant-process'

export const graphAddListeningEvent = (graph, palette)=> {

  // 连接线鼠标移入事件
  graph.on('edge:mouseenter', ({ cell }) => {
    // 添加删除按钮
    cell.addTools('button-remove')
  })

  // 连接线鼠标移出事件
  graph.on('edge:mouseleave', ({ cell }) => {
    // 移除删除按钮
    cell.removeTools('button-remove')
  })

  // 节点链接线点击事件
  graph.on('edge:click', ({ cell }) => {
    palette.selectNodeFun(cell.id, graph, 'edge')
    // 取消其他选择的节点
    $antProcess.cancelNoCurrentSelectNode(graph, cell.id)
    // 设置当前节点选中
    $antProcess.selectCurrentProcessNode(graph, cell.id)
  })

  // 添加线事件
  graph.on('edge:added', (args) => {
    console.log('edge:add', args)
  })

  // 选择节点
  graph.on('selection:changed', (e)=> {
    const { selected } = e
    for(let i = 0; i < selected.length; i++){
      const node = selected[i]
      node.setData({ isActive: true })
    }
  })
}